                                                
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.objects.Mesh;

/**
* RibbonSegment is like a plane but lets you define the vertices via x1,y1,x2,y2. 
* Z coord is extruded out.
* 
* by Felix Turner
* www.airtightinteractive.com
*/
class RibbonSegment extends Mesh
{
	/**
	* Number of segments horizontally. Defaults to 1.
	*/
	public var segmentsW :Number;

	/**
	* Number of segments vertically. Defaults to 1.
	*/
	public var segmentsH :Number;

	/**
	* Default size of Plane if not texture is defined.
	*/
	static public var RIBBON_WIDTH :Number = 200;

	/**
	* Default size of Plane if not texture is defined.
	*/
	static public var DEFAULT_SCALE :Number = 1;

	/**
	* Default value of segments.
	*/
	static public var DEFAULT_SEGMENTS :Number = 1;
	
	
	public function RibbonSegment( material:MaterialObject3D, x1:Number, y1:Number, x2:Number, y2:Number, initObject:Object )
	{
		super( material, new Array(), new Array(), initObject );

		this.segmentsW = DEFAULT_SEGMENTS;
		this.segmentsH = DEFAULT_SEGMENTS;

		var scale :Number = DEFAULT_SCALE;

		buildRibbonSegment( x1, y1, x2, y2 );
	}

	private function buildRibbonSegment( x1:Number, y1:Number, x2:Number, y2:Number)
	{
		
		var vertices :Array      = this.vertices;
		var faces    :Array      = this.faces;
		
		var a = new  Vertex3D( x1, y1, - RIBBON_WIDTH/2);
		var b = new Vertex3D( x2, y2, - RIBBON_WIDTH/2 ) ;
		var c =  new Vertex3D( x2, y2, RIBBON_WIDTH/2 ) ;
		var d =  new Vertex3D( x1, y1, RIBBON_WIDTH/2 ) ;

		vertices.push( a );
		vertices.push( b );
		vertices.push( c);
		vertices.push( d );

		faces.push( new Face3D( [ a, b, d ] ));
		faces.push( new Face3D( [ b, c, d ]) );
	}
		
}